package com.atguigu.spzx.manager.service.Impl;

import com.atguigu.spzx.manager.mapper.ProductSkuMapper;
import com.atguigu.spzx.manager.service.ProductSkuService;
import com.atguigu.spzx.model.entity.product.ProductSku;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * ClassName: ProductSkuServiceImpl
 * Package: com.atguigu.spzx.manager.service.Impl
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/6 16:50
 * @Version 1.0
 */
@Service
public class ProductSkuServiceImpl implements ProductSkuService {
    @Resource
    private ProductSkuMapper productSkuMapper;

    /**
     * 添加商品sku
     *
     * @param productSku
     */
    @Override
    public void save(ProductSku productSku) {
        productSkuMapper.save(productSku);
    }

    /**
     * 根据productId获取sku列表
     * @param id
     * @return
     */
    @Override
    public List<ProductSku> getByProductId(Long id) {
        return productSkuMapper.getByProductId(id);
    }

    /**
     * 根据id修改
     * @param productSku
     */
    @Override
    public void updateById(ProductSku productSku) {
        productSku.setUpdateTime(new Date());
        productSkuMapper.updateById(productSku);
    }

    /**
     * 根据productId删除
     * @param productId
     */
    @Override
    public void deleteById(Long productId) {
        productSkuMapper.deleteById(productId);
    }

    /**
     * 根据productId修改商品sku上下架状态
     * @param productId
     * @param status
     */
    @Override
    public void updateStatusByProductId(Long productId, Integer status) {
        ProductSku productSku = new ProductSku();
        productSku.setProductId(productId);
        productSku.setStatus(status);
        productSku.setUpdateTime(new Date());
        productSkuMapper.updateStatusByProductId(productSku );
    }
}
